﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmStructure.h"
#include "ICloneBehavior.h"
#include "NdbObjectSchematic.h"
#include "IExternalData.h"
#include "DbDataSchema.h"

namespace gcmp
{
    class IElement;
    class IDocument;
    class IParameter;

    class GM_STRUCTURE_EXPORT ModelLineUsedProfileData : public NdbObjectSchematic, public IExternalData
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, ModelLineUsedProfileData, gcmp::NdbObjectSchematic, 9A866349 - 69E0 - 4365 - A67E - F36A65A36502, gmstructure, IExternalData)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(ElementId, InstanceId)
        DBOBJECT_DATA_END

    public:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override
        {
            m_pOwnerElement = pOwnerElement;
            return true;
        }
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }

        void SetInstnaceId(ElementId id) { SetInstanceId__(id); }
        ElementId GetInstanceId() const { return GetInstanceId__(); }

    public:
        ModelLineUsedProfileData(IDocument* pDoc, const ElementId & ownerElementId, ElementId id = ElementId::InvalidID);

        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;
        virtual void ReportParents(IElementParentReporter& reporter) const override;
        virtual void GetCalculators(ICalculatorCollection* calculators) const override;

        virtual void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg = nullptr) override;
        virtual bool IsParameterModifiable(int paramDefId) const override;

        virtual void Report(const gcmp::ICopyContext & copyContext, gcmp::ICopyStrategyReporter& reporter) const override;
        virtual void UpdateAfterCopy(const ICopyContext& copyContext) override {};
        virtual void UpdateForWeakParentCopied(const IDocument* pDocumentFrom, const IElement* pSource, const IElement* pCopy) const override {};
        virtual bool ShouldBeCopiedTogether(const ICopyContext & copyContext) const override { return true; };
        virtual bool IsStrongParentsNeedCopied(void) const override { return true; };
        virtual bool CanBeCopied(std::wstring* pErrorMessage) const override { return true; };
        virtual bool Transform(const Matrix4d& matrix) override { return true; }

    private:
        IDocument* GetDocument() const;
        ElementId GetOwnerElementId() const;
        virtual NdbObject* GetTopOwnerObject() const override;
    };
}
